home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / compiler / const.ml < prev    next >
Encoding:
Text File  |  1993-09-24  |  778 b   |  40 lines  |  [TEXT/MPS ]

  1. (* Constants *)
  2.  
  3. #open "misc";;
  4.  
  5. type qualified_ident =
  6.   { qual: string;
  7.     id: string }
  8. ;;
  9.  
  10. type constr_tag =
  11.     ConstrExtensible of qualified_ident * int (* name of constructor & stamp *)
  12.   | ConstrRegular of int * int             (* tag number & number of constrs *)
  13. ;;
  14.  
  15. type atomic_constant =
  16.     ACint of int
  17.   | ACfloat of float
  18.   | ACstring of string
  19.   | ACchar of char
  20.  
  21. and struct_constant =
  22.     SCatom of atomic_constant
  23.   | SCblock of constr_tag * struct_constant list
  24. ;;
  25.  
  26. let const_unit =
  27.     SCblock(ConstrRegular(0,1), [])
  28. ;;
  29.  
  30. let int_of_atom = function
  31.     ACint i -> i
  32.   | ACchar c -> int_of_char c
  33.   | _ -> fatal_error "int_of_atom"
  34. ;;
  35.  
  36. let int_of_constr_tag = function
  37.     ConstrRegular(i,_) -> i
  38.   | ConstrExtensible _ -> fatal_error "int_of_constr_tag"
  39. ;;
  40.